@echo off
setlocal enabledelayedexpansion

set OUT_DIR=generated
set PROTOC=protoc
set PLUGIN=--plugin=protoc-gen-csharp="%PROTOC%"

if not exist "%OUT_DIR%" mkdir "%OUT_DIR%"

set COUNT=0
for %%f in (*.proto) do (
    echo [%%f]
    "%PROTOC%" --csharp_out="%OUT_DIR%" "%%f"
    if !errorlevel! neq 0 (
        echo compile failed: %%f
        pause
        exit /b 1
    )
    set /a COUNT+=1
)

echo.
echo Finished compile %COUNT% files, output dir: %OUT_DIR% !
pause